package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements UserService {
    public List<User> findAll() {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> list = mapper.findAll();
        MyBatisUtil.close(session);
        return list;
    }

    public User findById(Integer id) {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = mapper.findById(id);
        MyBatisUtil.close(session);
        return user;
    }

    public User findByNameAndPwd(int id, String username) {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = mapper.findByNameAndPwd(id,username);
        MyBatisUtil.close(session);
        return user;
    }

    public List<User> findCondition(User user) {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> list = mapper.findCondition(user);
        MyBatisUtil.close(session);
        return list;
    }

    public List<User> findByIds(List<Integer> lists) {
        SqlSession session = MyBatisUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> list = mapper.findByIds(lists);
        MyBatisUtil.close(session);
        return list;
    }
}
